// MainActivity.kt
package com.example.sunchaodong

import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.commit
import androidx.fragment.app.replace

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        findViewById<Button>(R.id.word_list_button).setOnClickListener {
            findViewById<TextView>(R.id.title).visibility = View.GONE
            findViewById<Button>(R.id.add_word_button).visibility = View.GONE
            supportFragmentManager.commit {
                replace<Wordfragment>(R.id.fragment_container_view)
                addToBackStack(null)
            }
        }

        findViewById<Button>(R.id.add_word_button).setOnClickListener {
            findViewById<TextView>(R.id.title).visibility = View.GONE
            findViewById<Button>(R.id.word_list_button).visibility = View.GONE
            supportFragmentManager.commit {
                replace<Wordaddfragment>(R.id.fragment_container_view)
                addToBackStack(null)
            }
        }
    }

    fun showMainActivityViews() {
        supportFragmentManager.popBackStack(null, androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE)
        findViewById<TextView>(R.id.title).visibility = View.VISIBLE
        findViewById<Button>(R.id.word_list_button).visibility = View.VISIBLE
        findViewById<Button>(R.id.add_word_button).visibility = View.VISIBLE
    }
}